package leetcode.editor.cn.q1_300.q100;

import leetcode.editor.cn.util.tree.btree.BTreeUtil;
import leetcode.editor.cn.util.tree.btree.TreeNode;

/**
 * @author qidi
 * @date 2022-01-06 16:08:01
 */
class Q0112_PathSum {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean hasPathSum(TreeNode root, int targetSum) {
            if (root == null) return false;

            if (root.left == null && root.right == null) return targetSum == root.val;

            return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val);
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0112_PathSum().new Solution();
        solution.hasPathSum(BTreeUtil.getInstance().generateFromArray(5, 4, 8, 11, null, 13, 4, 7, 2, null, null, null, 1), 22);
    }
}